package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.LhBaseEntityHelper;
import com.ruoyi.system.domain.LhGood;
import com.ruoyi.system.mapper.LhGoodMapper;
import com.ruoyi.system.service.LhGoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.concurrent.ExecutorService;

/**
 * @author 何金岳
 * @Description TODO
 * @createTime 2024年04月08日15时28分47秒
 * @since 1.0.0
 */
@Service
public class LhGoodServiceImpl implements LhGoodService {

    @Autowired
    private LhGoodMapper lhGoodMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public AjaxResult updateGood(LhGood lhGood) {
        Long id=lhGood.getId();
        LhGood dbGood= lhGoodMapper.selectById(id);
        if(dbGood==null){
            return AjaxResult.error("该商品信息不存在");
        }
        dbGood.setGoodName(lhGood.getGoodName());
        dbGood.setGoodNo(lhGood.getGoodNo());
        dbGood.setPrice(lhGood.getPrice());
        dbGood.setIsShow(lhGood.getIsShow());
        lhGoodMapper.updateLhGood(lhGood);
        return AjaxResult.success();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public AjaxResult insertLhGood(LhGood lhGood) {

        String goodName=lhGood.getGoodName();
        String goodNo=lhGood.getGoodNo();

        LhGood queryGood=new LhGood();
        queryGood.setGoodName(goodName);
        List<LhGood> nameGoodList=lhGoodMapper.pageListGood(queryGood);
        LhBaseEntityHelper.setForInsert(lhGood);
        lhGoodMapper.insertLhGood(lhGood);
        return AjaxResult.success();
    }

    @Override
    public List<LhGood> pagelist(LhGood lhGood) {
        return lhGoodMapper.pageListGood(lhGood);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteByIds(List<Long> idList){
        lhGoodMapper.deleteByIds(idList);
    }


    @Override
    public LhGood getGoodById(Long id) {
        LhGood lhGood= lhGoodMapper.selectById(id);
        return lhGood;
    }
}
